/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imageClipping;

import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputAdapter;

/**
 *
 * @author Alan
 */
public class ClipCreator extends MouseInputAdapter
{
    Clipping cropping;
    Point offset;
    boolean dragging;

    public ClipCreator(Clipping c)
    {
        cropping = c;
        offset = new Point();
        dragging = false;
    }

        @Override
    public void mousePressed(MouseEvent e)
    {
        offset = e.getPoint();
        dragging = true;
    }

        @Override
    public void mouseReleased(MouseEvent e)
    {
        dragging = false;
    }

        @Override
    public void mouseDragged(MouseEvent e)
    {
        if(dragging)
        {
            int x = e.getX() - offset.x;
            int y = e.getY() - offset.y;
            cropping.createClip(offset.x, offset.y,x,y);
            cropping.showClip = true;
            cropping.repaint();
        }
    }
}

